<div id="picAddress" class="tableform">
  <div class="piccontent">
    <{foreach from=$setting.pic item=data key=key}>
    <table  width="100%" cellpadding="0" cellspacing="0">
      <tr>
        <th><{t app="b2c"}>导航名称:<{/t}></th>
        <td>
          <input name="pic[<{$data.id}>][categoryname]" value="<{$data.categoryname}>">
        </td>
      </tr>
      <tr>
        <th><{t app="b2c"}>图片地址:<{/t}></th>
        <td>
          <input type=hidden name=pic[<{$data.id}>][id] value="<{$data.id}>">
          <input name='pic[<{$data.id}>][link]' class="imgsrc" id="pic[<{$data.id}>][link]"  value="<{$data.link}>">
          <input type=button value=上传图片 class="uploadbtn"><span>（推荐图片尺寸106px * 106px）</span>
        </td>
        <th><{t app="b2c"}>链接地址:<{/t}></th>
        <td>
          <input name="pic[<{$data.id}>][linktarget]" value="<{$data.linktarget}>">
        </td>
      </tr>
      <tr>
        <th><{t app="b2c"}>描述:<{/t}></th>
        <td>
          <input name="pic[<{$data.id}>][linkinfo]" value="<{$data.linkinfo}>">
        </td>
        <th><{t app="b2c"}>删除该图片及描述:<{/t}></th>
        <td><span onclick="$(this).getParent('table').destroy()"><{img src="bundle/delecate.gif" style="cursor:pointer;" alt=$___b2c="删除"|t:'b2c' title=$___b2c="删除"|t:'b2c' app="desktop"}></span></td>
      </tr>
    </table>
    <{/foreach}>
  </div>
  <{button label=$___b2c="添加图片"|t:'b2c' class="addimage" app="desktop" icon="btn_add.gif"}>
</div>

<script>
  (function(){
    var tag_type='table',tag_class='pic_items';

    document.getElement(".addimage").addEvent('click',function(){
      var i=new Date().getTime();
      var tpl='\
      <tr><th><{t app="b2c"}>导航名称:<{/t}></th>\
        <td><input name="pic['+i+'][categoryname]" value=""></td>\
      <tr><th><{t app="b2c"}>图片地址:<{/t}></th>\
      <td><input type=hidden name=pic['+i+'][id] value="'+i+'"><input name="pic['+i+'][link]" class="imgsrc">\
      <input type=button value=<{t app="b2c"}>上传图片<{/t}> class="uploadbtn" id="pic['+i+']"><span>（推荐图片尺寸106px * 106px）</span></td>\
      <th><{t app="b2c"}>链接地址:<{/t}></th>\
      <td><input name="pic['+i+'][linktarget]"></td></tr>\
      <th><{t app="b2c"}>删除该分类:<{/t}></th>\
      <td><span onclick="$(this).getParent(\'table\').destroy()"><{img src="bundle/delecate.gif" style="cursor:pointer;" alt=$___b2c="删除"|t:'b2c' title=$___b2c="删除"|t:'b2c' app="desktop"}></span></td>\
      </tr>';

      $('picAddress').getElement('.piccontent').adopt(new Element(tag_type,{'html':tpl,'width':'100%','class':tag_class}));

      $('pic['+i+']').addEvent('click',function(e){bindevent(this)});
    });


    $$(".piccontent .uploadbtn").addEvent('click',function(e){bindevent(this)});

    function bindevent(el){
      var target=$(el).getParent(tag_type).getElement('.imgsrc');
      var url=url='index.php?app=desktop&act=alertpages&goto='+encodeURIComponent("index.php?app=image&ctl=admin_manage&act=image_broswer&type=big");
      Ex_Loader('modedialog',function(){
        return new imgDialog(url,{onCallback:function(image_id,image_src){
          target.value=image_src;
        }});
      });
    }

  })();
</script>

